<!-- 毛坯仓 外加工收货 -->
<template>
  <pageTabelLayout>
    <template #pageHeader>
      <div class="search-form isheader" v-if="headerShow">
        <div>
          <a-form size="small" :model="pageData" layout="inline">
            <a-form-item label="来源单号" :style="{ width: '345px' }" label-col-flex="100px">
              <a-input allow-clear class="bacClass" v-model="pageData.sourceCode"/>
            </a-form-item>
            <a-form-item label="供应商名称" :style="{ width: '345px' }" label-col-flex="100px">
              <a-input allow-clear class="bacClass" v-model="pageData.supplierName"/>
            </a-form-item>
            <a-form-item label="订单号" :style="{ width: '345px' }" label-col-flex="100px">
              <a-input allow-clear class="bacClass" v-model="pageData.orderCode"/>
            </a-form-item>
            <a-form-item label="布号" :style="{ width: '345px' }" label-col-flex="100px">
              <a-input allow-clear class="bacClass" v-model="pageData.greyCode"/>
            </a-form-item>
            <a-form-item label="品名" :style="{ width: '345px' }" label-col-flex="100px">
              <a-input allow-clear class="bacClass" v-model="pageData.brandName"/>
            </a-form-item>
            <a-form-item label="客户名称" :style="{ width: '345px' }" label-col-flex="100px">
              <a-input allow-clear class="bacClass" v-model="pageData.customName"/>
            </a-form-item>
            <a-form-item label="收货来源" :style="{ width: '345px' }" label-col-flex="100px">
              <a-input allow-clear class="bacClass" v-model="pageData.deliverySourceName"/>
            </a-form-item>
            <a-form-item label="记录单号" :style="{ width: '345px' }" label-col-flex="100px">
              <a-input allow-clear class="bacClass" v-model="pageData.recordCode"/>
            </a-form-item>
            <a-form-item label="开单日期" :style="{ width: '345px' }" label-col-flex="100px">
              <a-date-picker popup-container="html" :style="{ width: '229px' }" class="bacClass"
                             v-model="pageData.dateStart"/>
            </a-form-item>
            <a-form-item label="至" :style="{ width: '345px' }" label-col-flex="100px">
              <a-date-picker popup-container="html" :style="{ width: '229px' }" class="bacClass"
                             v-model="pageData.dateEnd"/>
            </a-form-item>
          </a-form>
        </div>

      </div>

      <div class="my-divisders">
        <a-divider orientation="center">
          <icon-double-up v-if="headerShow" @click="headerShow = false" :strokeWidth="2" :size="18"/>
          <icon-double-down v-else @click="headerShow = true" :strokeWidth="2" :size="18"/>
        </a-divider>
      </div>
      <div style="float: right;">
        <Toolbar :items="toolbarList" @add="addHandler" @select="selectHandler" @del="deleteHandler"
                 @export="exports" @audit="audits">
        </Toolbar>
      </div>
    </template>
    <template #pageTabel>
      <a-tabs   :lazy-load="true" :justify="true" :default-active-key="tabsKeys" @change="tabsChanges">
        <a-tab-pane title="未处理" :key="1">
          <AgGridVuesCopys :rowHeight="33" :headerHeight="33" :suppressCopyRowsToClipboard="true"
                           rowSelection="multiple" @grid-ready="gridReady"
                           style="height: calc(100% - 45px)" :defaultColDef="defaultColDef" class='ag-theme-alpine'
                           :rowData="tableDataList"
                           :columnDefs="tc" :localeText="localeText1"></AgGridVuesCopys>
          <paginationCopys :page-size-options="pagingList1" :total="total" show-total show-jumper show-page-size
                           @change="PageSize" @page-size-change="change" style="justify-content: center"
                           :page-size="pagination.pageSize" :current="pagination.page"/>
        </a-tab-pane>
        <a-tab-pane title="已处理" :key="2">
          <AgGridVuesCopys :rowHeight="33" :headerHeight="33" :suppressCopyRowsToClipboard="true"
                           rowSelection="multiple" @grid-ready="gridReady2"
                           style="height: calc(100% - 45px)" :defaultColDef="defaultColDef2" class='ag-theme-alpine'
                           :rowData="tableDataList2"
                           :columnDefs="tc2" :localeText="localeText1"></AgGridVuesCopys>
          <paginationCopys :page-size-options="pagingList1" :total="total1" show-total show-jumper show-page-size
                           @change="PageSize" @page-size-change="change" style="justify-content: center"
                           :page-size="pagination.pageSize" :current="pagination.page"/>
        </a-tab-pane>
      </a-tabs>
    </template>
    <a-drawer :drawer-style="{ 'zIndex': 9999 }" :mask-closable="false" height="80%" :visible="pageData.showAdd8"
              unmountOnClose @ok="sideOk" @cancel="pageData.showAdd8 = false" cancel-text='关闭' ok-text='保存'
              placement="bottom">
      <template #title>
        {{ pageData.sideTitle }}
      </template>
      <div style="min-width:800px;">
        <div>
          <a-form ref="formRef" layout="inline" size="small" :model="objectOP">
            <a-form-item label="记录单号" :style="{ width: '345px' }" label-col-flex="100px">
              <a-input class="bacClass" v-model="objectOP.recordCode" disabled></a-input>
            </a-form-item>
            <a-form-item :style="{ width: '345px' }" label-col-flex="100px" label="开单日期" field="recordDate"
                         :validate-trigger="['change', 'blur']" :rules="[{ required: true, message: '开单日期必填' }]">
              <a-date-picker popup-container="html" :style="{ width: '229px' }" class="bacClass"
                             v-model="objectOP.recordDate"
                             :disabled="pageData.dataBoolean"/>
            </a-form-item>
            <a-form-item :style="{ width: '345px' }" label-col-flex="100px" label="收货来源"
                         :validate-trigger="['change', 'blur']" :rules="[{ required: true, message: '收货来源必填' }]"
                         field="deliverySourceName">
              <a-select popup-container="html" class="bacClass" :loading="loading" :allowClear="true"
                        @search="handleSearch"
                        v-model="objectOP.deliverySourceName" :filter-option="false" allow-search @focus="focusSel"
                        :disabled="pageData.dataBoolean">
                <a-option v-for="item in pageData.nameList" :value="item['detailName']">{{
                    item['detailName']
                  }}
                </a-option>
              </a-select>
            </a-form-item>
            <a-form-item :style="{ width: '345px' }" label-col-flex="100px" label="客户名称"
                         :validate-trigger="['change', 'blur']" :rules="[{ required: true, message: '客户名称必填' }]"
                         field="customName">
              <a-select popup-container="html" class="bacClass" :loading="loading" :allowClear="true"
                        @search="handleSearch1"
                        v-model="objectOP.customName" :filter-option="false" allow-search @focus="focusSel1"
                        :disabled="pageData.dataBoolean">
                <a-option v-for="item in pageData.nameList1" :value="item['customName']">{{
                    item['customName']
                  }}
                </a-option>
              </a-select>
            </a-form-item>
            <a-form-item :style="{ width: '345px' }" label-col-flex="100px" label="供应商名称"
                         :validate-trigger="['change', 'blur']" :rules="[{ required: true, message: '供应商名称必填' }]"
                         field="supplierName">
              <a-select popup-container="html" class="bacClass" :loading="loading" :allowClear="true"
                        @search="handleSearch2"
                        v-model="objectOP.supplierName" :filter-option="false" allow-search @focus="focusSel2"
                        :disabled="pageData.dataBoolean">
                <a-option v-for="item in pageData.nameList2" :value="item['providerName']">{{
                    item['providerName']
                  }}
                </a-option>
              </a-select>
            </a-form-item>
            <a-form-item label="坯布编号" :style="{ width: '345px' }" label-col-flex="100px">
              <a-input disabled class="bacClass" v-model="objectOP.greyCode"></a-input>
            </a-form-item>
            <a-form-item label="品名" :style="{ width: '345px' }" label-col-flex="100px">
              <a-input disabled class="bacClass" v-model="objectOP.brandName"></a-input>
            </a-form-item>
            <a-form-item label="单位" :style="{ width: '345px' }" label-col-flex="100px">
              <a-input disabled class="bacClass" v-model="objectOP.unit"></a-input>
            </a-form-item>
            <a-form-item label="订单号" :style="{ width: '345px' }" label-col-flex="100px">
              <a-input disabled class="bacClass" v-model="objectOP.orderCode"></a-input>
            </a-form-item>
            <a-form-item label="客户订单号" :style="{ width: '345px' }" label-col-flex="100px">
              <a-input disabled class="bacClass" v-model="objectOP.customOrderCode"></a-input>
            </a-form-item>
            <a-form-item label="尺寸" :style="{ width: '345px' }" label-col-flex="100px">
              <a-input disabled class="bacClass" v-model="objectOP.inch"></a-input>
            </a-form-item>
            <a-form-item label="收货备注" :style="{ width: '345px' }" label-col-flex="100px">
              <a-input class="bacClass" v-model="objectOP.remark" :disabled="pageData.dataBoolean"></a-input>
            </a-form-item>
            <a-form-item label="匹数" :style="{ width: '345px' }" label-col-flex="100px">
              <a-input-number disabled class="bacClass" v-model="objectOP.horseNum" :min="0"></a-input-number>
            </a-form-item>
            <a-form-item label="重量" :style="{ width: '345px' }" label-col-flex="100px">
              <a-input disabled class="bacClass" v-model="objectOP.weight"></a-input>
            </a-form-item>
            <a-form-item label="门幅" :style="{ width: '345px' }" label-col-flex="100px">
              <a-input disabled class="bacClass" v-model="objectOP.width"></a-input>
            </a-form-item>
            <a-form-item label="克重" :style="{ width: '345px' }" label-col-flex="100px">
              <a-input disabled class="bacClass" v-model="objectOP.gramWeight"></a-input>
            </a-form-item>
            <a-form-item label="纱批" :style="{ width: '345px' }" label-col-flex="100px">
              <a-input class="bacClass" v-model="objectOP.yarnBatch"
                       :disabled="pageData.dataBoolean"></a-input>
            </a-form-item>
            <a-form-item label="色号" :style="{ width: '345px' }" label-col-flex="100px">
              <a-input disabled class="bacClass" v-model="objectOP.colorCode"></a-input>
            </a-form-item>
            <a-form-item label="色称" :style="{ width: '345px' }" label-col-flex="100px">
              <a-input disabled class="bacClass" v-model="objectOP.colorName"></a-input>
            </a-form-item>
            <a-form-item label="织造序号" :style="{ width: '345px' }" label-col-flex="100px">
              <a-input class="bacClass" disabled v-model="objectOP.weaveCode"/>
            </a-form-item>
            <a-form-item label="记账员" :style="{ width: '345px' }" label-col-flex="100px">
              <a-input disabled class="bacClass" v-model="objectOP.recordPerson"></a-input>
            </a-form-item>
            <a-form-item label="来源单号" :style="{ width: '345px' }" label-col-flex="100px">
              <a-input disabled class="bacClass" v-model="objectOP.sourceCode"></a-input>
            </a-form-item>
            <a-form-item label="纱批1" :style="{ width: '345px' }" label-col-flex="100px">
              <a-input disabled class="bacClass" v-model="objectOP.yarnBatch1"></a-input>
            </a-form-item>
            <a-form-item label="纱批2" :style="{ width: '345px' }" label-col-flex="100px">
              <a-input disabled class="bacClass" v-model="objectOP.yarnBatch2"></a-input>
            </a-form-item>
          </a-form>
        </div>
      </div>
      <div style="margin: 5px 0px 15px 15px;" v-if="!pageData.dataBoolean">
        <el-button style="color:#165dff;" class="gesture" link @click="importHandler">导入EXCEL</el-button>
        <el-button style="color:#165dff;" class="gesture" link @click="lookSet">生成条码</el-button>
      </div>
      <AgGridVuesCopys :rowHeight="33" :headerHeight="33" :suppressCopyRowsToClipboard="true" rowSelection="multiple"
                       @grid-ready="gridReady1"
                       style="height:60%" :defaultColDef1="defaultColDef1" class='ag-theme-alpine'
                       :rowData="tableDataList1"
                       :columnDefs="dc" :localeText="localeText1"></AgGridVuesCopys>
    </a-drawer>
  </pageTabelLayout>
</template>
<script setup lang="ts">
import {
  useTable,
  useRowKey,
  useTableColumn,
  usePagination,
  useRowSelection,
} from "@/hooks/table";
import {ref, reactive} from "vue"
import {post, get} from "@/api/http"
import {localeText} from '@/api/aggridZw'

import Toolbar from "@/components/Toolbar.vue"
import {Message, Modal} from "@arco-design/web-vue"
import CorporateSectorCascader from '@/components/corporateSectorCascader/inde.vue'
import {FormInstance} from "@arco-design/web-vue/es/form";
import {EXELTABLE} from '@/utils/exportEXCEL';
import {pagingList} from "@/api/paging";
import {baseURL} from '../../../api/axios.config'
import axios from "axios";

const toolbarList: any = ref(['查询', '新增', '删除', '审核'])
let isIDs: any = ref(1);


function PageSize(val: any) {
  if (isIDs.value == 1) {
    pagination.page = val
    doRefresh();
  } else if (isIDs.value == 2) {
    pagination2.page = val
    doRefresh1();
  }
}

function change(val: any) {
  if (isIDs.value == 1) {
    pagination.pageSize = val
    doRefresh();
  } else {
    pagination2.pageSize = val
    doRefresh1();
  }
}


const headerShow = ref(true)

const tableDataList = ref([])

const tableDataList2: any = ref([])

const tableDataList1 = ref([])


const gridOption = ref()
const gridReady = (params: any) => {
  gridOption.value = params.api
}

const gridOption2 = ref()
const gridReady2 = (params: any) => {
  gridOption2.value = params.api
}

const gridOption1 = ref()
const gridReady1 = (params: any) => {
  gridOption1.value = params.api
}

const defaultColDef = {
  sortable: true,
  resizable: true,
  filter: true,
}

const defaultColDef2 = {
  sortable: true,
  resizable: true,
  filter: true,
}

const defaultColDef1 = {
  sortable: true,
  resizable: true,
  filter: true,
}

const localeText1: any = ref(localeText)

const tc = [
  {
    showRowGroup: 'hide_def',
    "headerName": "",
    "checkboxSelection": true,
    "headerCheckboxSelection": true,
    "pinned": "left",
    "width": 50,
    resizable: false,
    filter: false,
    sortable: false,
    minWidth: 50,
    maxWidth: 50,
    lockPosition: "left",
  },
  {
    headerName: '记录单号',
    field: 'recordCode',
    width: 150,
    filter: 'recordCode',
  },
  {
    headerName: '开单日期',
    field: 'recordDate',
    width: 150
  },
  {
    headerName: '收货来源',
    field: 'deliverySourceName',
    width: 150
  },
  {
    headerName: '客户名称',
    field: 'customName',
    width: 150
  },
  {
    headerName: '供应商名称',
    field: 'supplierName',
    width: 150
  },
  {
    headerName: '布号',
    field: 'greyCode',
    width: 150
  },
  {
    headerName: '品名',
    field: 'brandName',
    width: 150
  },
  {
    headerName: '单位',
    field: 'unit',
    width: 150
  },
  {
    headerName: '订单号',
    field: 'orderCode',
    width: 150
  },
  {
    headerName: '客户订单号',
    field: 'customOrderCode',
    width: 150
  },
  {
    headerName: '尺寸',
    field: 'inch',
    width: 150
  },
  {
    headerName: '匹数',
    field: 'horseNum',
    width: 150
  },
  {
    headerName: '重量',
    field: 'weight',
    width: 150
  },
  {
    headerName: '门幅',
    field: 'width',
    width: 150
  },
  {
    headerName: '克重',
    field: 'gramWeight',
    width: 150
  },
  {
    headerName: '纱批',
    field: 'yarnBatch',
    width: 150
  },
  {
    headerName: '色号',
    field: 'colorCode',
    width: 150
  },
  {
    headerName: '色称',
    field: 'colorName',
    width: 150
  },
  {
    headerName: '织造序号',
    field: 'weaveCode',
    width: 150
  },
  {
    headerName: '记账员',
    field: 'recordPerson',
    width: 150
  },
  {
    headerName: '来源单号',
    field: 'sourceCode',
    width: 150
  },
  {
    headerName: '纱批1',
    field: 'yarnBatch1',
    width: 150
  },
  {
    headerName: '纱批2',
    field: 'yarnBatch2',
    width: 150
  },
  {
    headerName: '收货备注',
    field: 'remark',
    width: 150
  },
  {
    headerName: '状态',
    field: 'infoState',
    pinned: 'right',
    width: 150,
    cellRenderer: {
      template: `
        <a-space>
          <el-tag v-if="barcodeState == 0" type="warning" class="gesture">待生成</el-tag>
          <el-tag v-if="barcodeState == 1" type="success" class="gesture">已生成</el-tag>
          <el-tag type="warning" class="gesture">未审核</el-tag>
        </a-space>
      `,
      setup(props: any) {
        return {
          auditState: props.params.data.auditState,
          barcodeState: props.params.data.barcodeState
        }
      }
    }
  },
  {
    headerName: '操作',
    field: 'id',
    pinned: 'right',
    width: 150,
    cellRenderer: {
      template: `
        <el-button style="color:#165dff;" @click="a" class="gesture" link>修改</el-button>
      `,
      setup(props: any) {
        const a = () => {
          editHandler(props.params.data)
        }
        return {
          a
        }
      }
    }
  }
]

const tc2 = [
  {
    showRowGroup: 'hide_def',
    "headerName": "",
    "checkboxSelection": true,
    "headerCheckboxSelection": true,
    "pinned": "left",
    "width": 50,
    resizable: false,
    filter: false,
    sortable: false,
    minWidth: 50,
    maxWidth: 50,
    lockPosition: "left",
  },
  {
    headerName: '记录单号',
    field: 'recordCode',
    width: 150,
    filter: 'recordCode',
  },
  {
    headerName: '开单日期',
    field: 'recordDate',
    width: 150
  },
  {
    headerName: '收货来源',
    field: 'deliverySourceName',
    width: 150
  },
  {
    headerName: '客户名称',
    field: 'customName',
    width: 150
  },
  {
    headerName: '供应商名称',
    field: 'supplierName',
    width: 150
  },
  {
    headerName: '布号',
    field: 'greyCode',
    width: 150
  },
  {
    headerName: '品名',
    field: 'brandName',
    width: 150
  },
  {
    headerName: '单位',
    field: 'unit',
    width: 150
  },
  {
    headerName: '订单号',
    field: 'orderCode',
    width: 150
  },
  {
    headerName: '客户订单号',
    field: 'customOrderCode',
    width: 150
  },
  {
    headerName: '尺寸',
    field: 'inch',
    width: 150
  },
  {
    headerName: '匹数',
    field: 'horseNum',
    width: 150
  },
  {
    headerName: '重量',
    field: 'weight',
    width: 150
  },
  {
    headerName: '门幅',
    field: 'width',
    width: 150
  },
  {
    headerName: '克重',
    field: 'gramWeight',
    width: 150
  },
  {
    headerName: '纱批',
    field: 'yarnBatch',
    width: 150
  },
  {
    headerName: '色号',
    field: 'colorCode',
    width: 150
  },
  {
    headerName: '色称',
    field: 'colorName',
    width: 150
  },
  {
    headerName: '织造序号',
    field: 'weaveCode',
    width: 150
  },
  {
    headerName: '记账员',
    field: 'recordPerson',
    width: 150
  },
  {
    headerName: '来源单号',
    field: 'sourceCode',
    width: 150
  },
  {
    headerName: '纱批1',
    field: 'yarnBatch1',
    width: 150
  },
  {
    headerName: '纱批2',
    field: 'yarnBatch2',
    width: 150
  },
  {
    headerName: '收货备注',
    field: 'remark',
    width: 150
  },
  {
    headerName: '状态',
    field: 'infoState',
    pinned: 'right',
    width: 150,
    cellRenderer: {
      // template: `
      // <a-button v-if="barcodeState == 0" status="success">待生成</a-button>
      // <a-button v-else="barcodeState == 1" type="dashed" status="success">已生成</a-button>
      // <a-button type="dashed" status="success">未审核</a-button>

      // `,
      template: `
        <a-space>
          <el-tag v-if="barcodeState == 0" type="success" class="gesture">待生成</el-tag>
          <el-tag v-if="barcodeState == 1" type="success" class="gesture">已生成</el-tag>
          <el-tag type="success" class="gesture">已审核</el-tag>
        </a-space>
      `,
      setup(props: any) {
        return {
          auditState: props.params.data.auditState,
          barcodeState: props.params.data.barcodeState
        }
      }
    }
  },
  {
    headerName: '操作',
    field: 'id',
    pinned: 'right',
    width: 150,
    cellRenderer: {
      template: `
        <el-button style="color:#165dff;" @click="a" class="gesture" link>详情</el-button>
      `,
      setup(props: any) {
        const a = () => {
          editHandler1(props.params.data)
        }
        return {
          a
        }
      }
    }
  }
]
const dc = [
  {
    showRowGroup: 'hide_def',
    "headerName": "",
    "checkboxSelection": true,
    "headerCheckboxSelection": true,
    "pinned": "left",
    "width": 50,
    resizable: false,
    filter: false,
    sortable: false,
    minWidth: 50,
    maxWidth: 50,
    lockPosition: "left",
  },
  {
    headerName: '匹号',
    field: 'horseNo',
    width: 150,
  },
  {
    headerName: '送货车号',
    field: 'carPlate',
    width: 150
  },
  {
    headerName: '重量',
    field: 'weight',
    width: 150
  },
  {
    headerName: '条码号',
    field: 'barcode',
    width: 250
  },
  {
    headerName: '备注',
    field: 'remark',
    width: 150
  },
]
const objectOP = reactive<{
  recordCode: any,
  recordDate: number,
  deliverySourceName: any,
  customName: any,
  supplierName: any,
  greyCode: any,
  brandName: any,
  unit: any,
  orderCode: any,
  customOrderCode: any,
  inch: any,
  horseNum: any,
  weight: any,
  width: any,
  gramWeight: any,
  yarnBatch: any,
  colorName: any,
  colorCode: any,
  weaveCode: any,
  recordPerson: any,
  sourceCode: any,
  yarnBatch1: any,
  yarnBatch2: any,
  id: any,
  remark: any,
  barcodeState: number,
  BlankDeliveryDetail: any[],
}>
({
  barcodeState: 0,
  id: null,
  recordCode: '',
  recordDate: 0,
  deliverySourceName: '',
  customName: '',
  supplierName: '',
  greyCode: '',
  brandName: '',
  unit: '',
  orderCode: '',
  customOrderCode: '',
  inch: '',
  horseNum: 0,
  weight: '',
  width: '',
  gramWeight: '',
  yarnBatch: '',
  colorCode: '',
  colorName: '',
  weaveCode: '',
  recordPerson: '',
  sourceCode: '',
  yarnBatch1: '',
  yarnBatch2: '',
  remark: '',
  BlankDeliveryDetail: [],

});
const pageData = reactive<{
  dutymachineState: any,
  sideTitle: string,
  showAdd8: boolean,
  pageLoading: boolean,
  dataBoolean: boolean,
  sourceCode: any,
  supplierName: any,
  orderCode: any,
  greyCode: any,
  brandName: any,
  customName: any,
  deliverySourceName: any,
  recordCode: any,
  dateStart: any,
  dateEnd: any,
  nameList: any[],
  nameList1: any[],
  nameList2: any[],
}>({
  sideTitle: "新增收货单",
  dutymachineState: 0,
  showAdd8: false,
  pageLoading: false,
  dataBoolean: false,
  sourceCode: '',
  supplierName: '',
  orderCode: '',
  greyCode: '',
  brandName: '',
  customName: '',
  deliverySourceName: '',
  recordCode: '',
  dateStart: '',
  dateEnd: '',
  nameList: [],
  nameList1: [],
  nameList2: [],
});

const editHandler = (record: any) => {
  console.log(record);
  pageData.dataBoolean = false
  for (var key in record) {
    objectOP[key] = record[key]
  }
  post({
    url: "/dwWms/BlankDeliveryDetail/getList",
    data: {blankDeliveryId: record.id}
  }).then((res: any) => {
    if (res.code === 200) {
      tableDataList1.value = res.data
    }
  })
  pageData.sideTitle = '修改收货单';
  pageData.showAdd8 = true;

}
const editHandler1 = (record: any) => {
  console.log(record);
  for (var key in record) {
    objectOP[key] = record[key]
  }
  post({
    url: "/dwWms/BlankDeliveryDetail/getList",
    data: {blankDeliveryId: record.id}
  }).then((res: any) => {
    if (res.code === 200) {
      tableDataList1.value = res.data
    }
  })
  pageData.dataBoolean = true
  pageData.sideTitle = '收货单详情';
  pageData.showAdd8 = true;

}
const addHandler = () => {
  for (var key in objectOP) {
    if (key == "id") {
      objectOP[key] = null;

    } else {
      objectOP[key] = '';
    }
  }
  tableDataList1.value = []
  post({
    url: "/dwWms/BlankDelivery/getCodeGenerate",
    data: {}
  }).then((res: any) => {
    if (res.code === 200) {
      objectOP.recordCode = res.data
      let numbers = res.data.match(/\d+/g)
      objectOP.weaveCode = parseInt(numbers[0], 10)
    }
  })
  pageData.sideTitle = "新增收货单";
  pageData.showAdd8 = true;
}
const selectHandler = () => {
  if (tabsKeys.value == 1) {
    doRefresh()
  } else if (tabsKeys.value == 2) {
    doRefresh1()
  }
}

const tabsKeys = ref(1)

const tabsChanges = (e: any) => {
  tabsKeys.value = e
  if (e == 1) {
    doRefresh()
    toolbarList.value = ['查询', '新增', '删除', '审核']
  } else if (e == 2) {
    doRefresh1()
    toolbarList.value = ['查询', '导出']
  }
}
// 生成条码事件
const lookSet = (record: any) => {
  tableDataList1.value.forEach((o: any) => {
    o.barcode = objectOP.weaveCode + o.horseNo + o.carPlate
  })
  if (tableDataList1.value['barcode'] != '') {
    objectOP.barcodeState = 1
  } else {
    return
  }
}
// 新增事件
const formRef = ref<FormInstance>();
const sideOk = () => {
  objectOP.BlankDeliveryDetail = tableDataList1.value
  formRef.value?.validate().then((err) => {
    if (!err) {
      if (pageData.sideTitle === "新增收货单") {
        post({
          url: "/dwWms/BlankDelivery/insertList",
          data: objectOP
        }).then((res: any) => {
          if (res.code === 200) {
            formRef.value?.resetFields();
            pageData.showAdd8 = false;
            Message.success({
              content: "新增成功",
              duration: 5000,
            });
            doRefresh();
          } else {
            Message.error({
              content: res.message,
              duration: 5000,
            });
          }
        })
      } else {
        post({
          url: "/dwWms/BlankDelivery/updateList",
          data: objectOP
        }).then((res: any) => {
          if (res.code === 200) {
            formRef.value?.resetFields();
            pageData.showAdd8 = false;
            Message.success({
              content: "修改成功",
              duration: 5000,
            });
            doRefresh();
          } else {
            Message.error({
              content: res.message,
              duration: 5000,
            });
          }
        })
      }
    }
  })
}
// 收货来源下拉框下拉数据
const focusSel = () => {
  selCxAll({"codeType": ""});
}
const options = ref<any>(pageData.nameList);
const loading = ref(false);
const handleSearch = (value: any) => {
  if (value) {
    const ob = {codeType: value, deleteState: 0}
    loading.value = true;
    selCxAll(ob);
    options.value = pageData.nameList;
    loading.value = false;
  } else {
    options.value = []
  }
};

function selCxAll(val: any) {
  post({
    url: "/dict/dictTypeDetail/getList",
    data: {codeType: 30}
  }).then(({data, code}: any) => {
    if (code === 200) {
      pageData.nameList = data;
    } else {
      Message.error({
        content: "查询失败！",
        duration: 5000,
      });
    }
  });
}

// 客户名称下拉框下拉数据
const focusSel1 = () => {
  selCxAll1({"customName": ""});
}
const options1 = ref<any>(pageData.nameList1);
const loading1 = ref(false);
const handleSearch1 = (value: any) => {
  if (value) {
    const ob = {customName: value, deleteState: 0}
    loading1.value = true;
    selCxAll1(ob);
    options1.value = pageData.nameList1;
    loading1.value = false;
  } else {
    options1.value = []
  }
};

function selCxAll1(val: any) {
  post({
    url: "/aps/custom/getDropValue",
    data: val
  }).then(({data, code}: any) => {
    if (code === 200) {
      pageData.nameList1 = data;
    } else {
      Message.error({
        content: "查询失败！",
        duration: 5000,
      });
    }
  });
}

// 供应商名称下拉框下拉数据
const focusSel2 = () => {
  selCxAll2({"providerName": ""});
}
const options2 = ref<any>(pageData.nameList2);
const loading2 = ref(false);
const handleSearch2 = (value: any) => {
  if (value) {
    const ob = {providerName: value, deleteState: 0}
    loading2.value = true;
    selCxAll2(ob);
    options2.value = pageData.nameList2;
    loading2.value = false;
  } else {
    options2.value = []
  }
};

function selCxAll2(val: any) {
  post({
    url: "/dwPurchase/Provider/getFieldValue",
    data: val
  }).then(({data, code}: any) => {
    if (code === 200) {
      pageData.nameList2 = data;
    } else {
      Message.error({
        content: "查询失败！",
        duration: 5000,
      });
    }
  });
}

// 未审核页面审核方法
const audits = () => {
  if (gridOption.value.getSelectedRows().length === 0) {
    Message.error('请先勾选')
    return;
  }
  Modal.confirm({
    title: '系统提示',
    content: '是否审核此订单',
    onOk() {
      post({
        url: "/dwWms/BlankDelivery/setAudit",
        // data: auditStateId,
        data: gridOption.value.getSelectedRows().map((item: any) => {
          return {id: item.id, auditState: 1}
        })
      }).then((res: any) => {
        if (res.code === 200) {
          doRefresh();
          Message.success('审核通过')
          // selectedRowKeys.value = []
        } else {
          Message.error(res.message)
        }
      })
    }
  })
}
// 删除事件
const deleteHandler = () => {
  if (gridOption.value.getSelectedRows().length === 0) {
    Message.error('请先勾选')
    return;
  }
  Modal.confirm({
    title: "系统提示",
    content: "确认删除选中的数据?",
    onOk() {
      post({
        url: "/dwWms/BlankDelivery/delete",
        data: gridOption.value.getSelectedRows().map((o: any) => {
          return o.id
        })
      }).then(({code, data, message}: any) => {
        if (code === 200) {
          Message.success({
            content: "删除成功",
            duration: 5000,
          });

          pagination.page = 1
          doRefresh();

        } else {
          Message.error({
            content: '删除失败',
            duration: 5000,
          });
        }

      });
    },
  });
};
// 查询事件
const total = ref(10);
const total1 = ref(10);
const pagingList1: any = ref(pagingList)
const page = ref(1);
const size = ref(10);

function doRefresh() {
  pageData.pageLoading = true
  post({
    url: "/dwWms/BlankDelivery/getPage",
    data: {
      page: pagination.page,
      size: pagination.pageSize,
      sourceCode: pageData.sourceCode,
      supplierName: pageData.supplierName,
      orderCode: pageData.orderCode,
      greyCode: pageData.greyCode,
      brandName: pageData.brandName,
      customName: pageData.customName,
      deliverySourceName: pageData.deliverySourceName,
      recordCode: pageData.recordCode,
      dateStart: pageData.dateStart,
      dateEnd: pageData.dateEnd,
      auditState: 0,
      deleteState: 0,
    },
  })
      .then(({data, code}: any) => {
        if (code === 200) {

          table.handleSuccess(data.list);
          gridOption.value.setRowData(data.list)
          total.value = data.total;

        }
      })
      .catch(console.log).finally(() => {
    pageData.pageLoading = false
  })
}

// 已审核查询
function doRefresh1() {
  pageData.pageLoading = true
  post({
    url: "/dwWms/BlankDelivery/getPage",
    data: {
      page: pagination.page,
      size: pagination.pageSize,
      sourceCode: pageData.sourceCode,
      supplierName: pageData.supplierName,
      orderCode: pageData.orderCode,
      greyCode: pageData.greyCode,
      brandName: pageData.brandName,
      customName: pageData.customName,
      deliverySourceName: pageData.deliverySourceName,
      recordCode: pageData.recordCode,
      dateStart: pageData.dateStart,
      dateEnd: pageData.dateEnd,
      auditState: 1,
      deleteState: 0,
    },
  })
      .then(({data, code}: any) => {
        if (code === 200) {

          table.handleSuccess(data.list);
          gridOption2.value.setRowData(data.list)
          total1.value = data.total;

        }
      })
      .catch(console.log).finally(() => {
    pageData.pageLoading = false
  })
}

const {selectedRowKeys, onSelectionChange} = useRowSelection();
const pagination = usePagination(doRefresh);
const pagination2 = usePagination(doRefresh1);
const table = useTable();
const rowKey = useRowKey("id");
//导出
// const exports = () => {
//     if (gridOption2.value.getSelectedRows().length === 0) {
//         Message.error('请先勾选');
//         return
//     } else {
//         let idList: any = []
//         gridOption2.value.getSelectedRows().forEach(function (o: any) {
//             idList.push(o['id'])
//         })
//         //将表头拼接出来
//         let head = "<th>记录单号</th><th>开单日期</th><th>收货来源</th><th>客户名称</th><th>供应商名称</th><th>布号</th><th>品名</th><th>单位</th><th>订单号</th><th>客户订单号</th><th>尺寸</th><th>匹数</th><th>重量</th><th>门幅</th><th>克重</th><th>纱批</th><th>色号</th><th>色称</th><th>布号</th><th>织造序号</th><th>记账员</th><th>来源单号</th><th>纱批1</th><th>纱批2</th><th>收货备注</th><th>状态</th>"
//         //拿到当前表格数据与勾选的行做筛选

//         let nowRow = tableDataList.value.filter(function (o) {
//             return (gridOption2.value.getSelectedRows().map((o: any) => { return o.id })).indexOf(o["id"]) !== -1;
//         })
//         let body = "";
//         nowRow.forEach(function (o) {
//             body += "<tr><td>" + o["recordCode"] + "</td>";
//             body += "<td>" + (o["recordDate"] == undefined ? "" : o["recordDate"]) + "</td>";
//             body += "<td>" + (o["deliverySourceName"] == undefined ? "" : o["deliverySourceName"]) + "</td>";
//             body += "<td>" + (o["customName"] == undefined ? "" : o["customName"]) + "</td>";
//             body += "<td>" + (o["supplierName"] == undefined ? "" : o["supplierName"]) + "</td>";
//             body += "<td>" + (o["greyCode"] == undefined ? "" : o["greyCode"]) + "</td>";
//             body += "<td>" + (o["brandName"] == undefined ? "" : o["brandName"]) + "</td>";
//             body += "<td>" + (o["unit"] == undefined ? "" : o["unit"]) + "</td>";
//             body += "<td>" + (o["orderCode"] == undefined ? "" : o["orderCode"]) + "</td>";
//             body += "<td>" + (o["customOrderCode"] == undefined ? "" : o["customOrderCode"]) + "</td>";
//             body += "<td>" + (o["inch"] == undefined ? "" : o["inch"]) + "</td>";
//             body += "<td>" + (o["horseNum"] == undefined ? "" : o["horseNum"]) + "</td>";
//             body += "<td>" + (o["weight"] == undefined ? "" : o["weight"]) + "</td>";
//             body += "<td>" + (o["width"] == undefined ? "" : o["width"]) + "</td>";
//             body += "<td>" + (o["gramWeight"] == undefined ? "" : o["gramWeight"]) + "</td>";
//             body += "<td>" + (o["yarnBatch"] == undefined ? "" : o["yarnBatch"]) + "</td>";
//             body += "<td>" + (o["colorCode"] == undefined ? "" : o["colorCode"]) + "</td>";
//             body += "<td>" + (o["colorName"] == undefined ? "" : o["colorName"]) + "</td>";
//             body += "<td>" + (o["weaveCode"] == undefined ? "" : o["weaveCode"]) + "</td>";
//             body += "<td>" + (o["recordPerson"] == undefined ? "" : o["recordPerson"]) + "</td>";
//             body += "<td>" + (o["sourceCode"] == undefined ? "" : o["sourceCode"]) + "</td>";
//             body += "<td>" + (o["yarnBatch1"] == undefined ? "" : o["yarnBatch1"]) + "</td>";
//             body += "<td>" + (o["yarnBatch2"] == undefined ? "" : o["yarnBatch2"]) + "</td>";
//             body += "<td>" + (o["remark"] == undefined ? "" : o["remark"]) + "</td>";

//             body += "<td>" + (o["infoState"] == undefined ? "" : o["infoState"]) + "</td>";
//             body += "</tr>";
//         })
//         tableToXlsx(head, '毛坯收货列表', body)
//         // console.log(table)
//     }
// }

// function tableToXlsx(head: any, filename: any, body: any) {
//     const uri = 'data:application/vnd.ms-excel;base64,',
//         template = `<html>
//             <head><meta charset="UTF-8"></head>
//             <body><table border="1"><tr>${head}</tr>${body}</table></body>
//         </html>`;

//     const a = document.createElement('a');
//     a.href = uri + window.btoa(unescape(encodeURIComponent(template)));
//     a.download = filename;
//     a.click();
//     document.removeChild(a);
// }
const exports = () => {
  if (gridOption2.value.getSelectedRows().length === 0) {
    Message.error('请先勾选')
    return;
  } else {
    EXELTABLE(tc2, gridOption2.value.getSelectedRows(), '外加工收货列表')
  }

}
//导入
const importHandler = () => {
  if (objectOP.recordDate != null && objectOP.deliverySourceName != '' && objectOP.customName != '' && objectOP.supplierName != '') {
    const inputEle: HTMLInputElement = document.createElement('input')
    inputEle.type = 'file'
    inputEle.id = 'fileUploadExcel'
    inputEle.accept = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, application/vnd.ms-excel'
    inputEle.addEventListener('change', (e) => {
      const formData = new FormData()
      if (inputEle.files !== null) {
        formData.append('file', inputEle.files[0] || '')
      } else {
        Message.warning('未选择文件！');
        return
      }
      pageData.pageLoading = true
      axios.post(baseURL + '/dwWms/BlankDelivery/importModelData', formData, {
        headers: {
          "Content-Type": 'multipart/form-data',
          "token": sessionStorage.getItem('USER-TOKEN-KEY')
        },
      }).then((result) => {
        if (result.data['code'] === 200) {
          Message.success('导入成功')
          // objectOP = result.data.data.BlankDelivery
          objectOP.brandName = result.data.data.BlankDelivery.brandName
          objectOP.greyCode = result.data.data.BlankDelivery.greyCode

          objectOP.unit = result.data.data.BlankDelivery.unit
          objectOP.orderCode = result.data.data.BlankDelivery.orderCode
          objectOP.customOrderCode = result.data.data.BlankDelivery.customOrderCode
          objectOP.inch = result.data.data.BlankDelivery.inch
          objectOP.horseNum = result.data.data.BlankDelivery.horseNum
          objectOP.weight = result.data.data.BlankDelivery.weight
          objectOP.width = result.data.data.BlankDelivery.width
          objectOP.gramWeight = result.data.data.BlankDelivery.gramWeight
          objectOP.colorCode = result.data.data.BlankDelivery.colorCode
          objectOP.colorName = result.data.data.BlankDelivery.colorName
          objectOP.recordPerson = result.data.data.BlankDelivery.recordPerson
          objectOP.sourceCode = result.data.data.BlankDelivery.sourceCode
          objectOP.yarnBatch1 = result.data.data.BlankDelivery.yarnBatch1
          objectOP.yarnBatch2 = result.data.data.BlankDelivery.yarnBatch2

          tableDataList1.value = result.data.data.BlankDeliveryDetail
          // console.log(result.data.data.BlankDelivery, objectOP, '我的爱也曾经深深温暖你的心灵');

        } else {
          Message.error(result.data.message)
        }

      }).finally(() => {
        pageData.pageLoading = false
        // doRefresh()
      })
    })
    inputEle.click()
  } else {
    Message.warning('请将上方必填项填写完整！');
    return
  }

}

</script>
<script lang="ts">
export default {
  name: "ReceiptList0",
}
</script>
<style scoped lang="less">
:deep(.ag-cell) {
  border-right: 1px solid #dde2eb;
}

:deep(.ag-header-cell) {
  border-right: 1px solid #dde2eb;
}

:deep(.ag-cell-value) {
  user-select: initial;
  -moz-user-select: text;
  -ms-user-select: text;
  -webkit-user-select: text;
}
</style>
